<template>
  <!-- slot 插槽表示可以把元素放进去 -->
  <transition name="drop">
    <div class="top-tip" v-show="showFlag" @click.stop="hide">
      <slot></slot>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
export default {
  props: {
    delay: {
      type: Number,
      default: 1500
    }
  },
  data () {
    return {
      showFlag: false
    }
  },
  methods: {
    show () {
      this.showFlag = true
      // 反复调用会有多个定时器 我们清除
      clearTimeout(this.timer)
      this.timer = setTimeout(() => {
        this.hide()
      }, this.delay)
    },
    hide () {
      this.showFlag = false
    }
  }
}
</script>

<style lang="stylus" scoped rel="stylesheet/stylus">
  @import '~common/stylus/variable';

  .top-tip {
    position: fixed;
    top: 0;
    width: 100%;
    background: $color-dialog-background;
    z-index: 500;

    &.drop-enter-active, &.drop-leave-active {
      transition: all 0.4s;
    }

    &.drop-enter, &.drop-leave-to {
      transform: translateY(-100%);
    }
  }
</style>
